// 用于发送 Ajax请求
import './config'
import config from "./config";
export default (url, data, method='GET') => {
    // new Promise初始化状态为pending
    return new Promise((resolve, reject) => {
        wx.request({
            url: config.host + url,
            data,
            method,
            headers : {
                cookies: wx.getStorageSync("cookies")?wx.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U') !== -1):''
            },
            success: (res) => {
                if(data.isLogin) {
                    wx.setStorage('cookies', res.cookies)
                }
                // console.log(res)
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}



